// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

#region File Information
//-----------------------------------------------------------------------------
// Human.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
#endregion

namespace HexTD
{
	class Human : Player
	{
		#region Fields/Constants
		//Drag variables to hold first and last gesture samples
		GestureSample? prevSample;
		GestureSample? firstSample;
		public bool isDragging;
		// Constant for longest distance possible between drag points
		readonly float maxDragDelta = (new Vector2(480, 800)).Length();
		// Textures & position & spriteEffects used for Catapult
		float arrowScale;

		Vector2 catapultPosition = new Vector2(140, 332);
		#endregion

		#region Initialization
		public Human(Game game)
			: base(game)
		{
		}

		public Human(Game game, SpriteBatch screenSpriteBatch)
			: base(game, screenSpriteBatch)
		{
		}

		public override void Initialize()
		{
			base.Initialize();
		}
		#endregion

		#region Handle Input
		/// <summary>
		/// Function processes the user input
		/// </summary>
		/// <param name="gestureSample"></param>
		public void HandleInput(GestureSample gestureSample)
		{
			// Process input only if in Human's turn
			if (IsActive)
			{
				// Process any Drag gesture
				if (gestureSample.GestureType == GestureType.FreeDrag)
				{
					// If drag just began save the sample for future 
					// calculations and start Aim "animation"
					if (null == firstSample)
					{
						firstSample = gestureSample;
					}

					// save the current gesture sample 
					prevSample = gestureSample;

					// calculate the delta between first sample and current
					// sample to present visual sound on screen
					Vector2 delta = prevSample.Value.Position -
						firstSample.Value.Position;
					float baseScale = 0.001f;
					arrowScale = baseScale * delta.Length();
					isDragging = true;
				}
				else if (gestureSample.GestureType == GestureType.DragComplete)
				{
					// calc velocity based on delta between first and last
					// gesture samples
					if (null != firstSample)
					{
						Vector2 delta = prevSample.Value.Position -
							firstSample.Value.Position;
					}

					// turn off dragging state
					ResetDragState();
				}
			}
		}
		#endregion

		#region Draw
		public override void Draw(GameTime gameTime)
		{
			if (isDragging)
				DrawDragArrow(arrowScale);

			base.Draw(gameTime);
		}

		public void DrawDragArrow(float arrowScale)
		{
			//spriteBatch.Draw(arrow, catapultPosition + new Vector2(0, -40),
			//  null, Color.Blue, 0,
			//  Vector2.Zero, new Vector2(arrowScale, 0.1f), SpriteEffects.None, 0);
		}
		#endregion

		/// <summary>
		/// Turn off dragging state and reset drag related variables
		/// </summary>
		public void ResetDragState()
		{
			firstSample = null;
			prevSample = null;
			isDragging = false;
		}
	}
}
